package com.threeox.httplibrary.request;

import com.threeox.httplibrary.utils.Exceptions;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 *
 * @ClassName: PostStringRequest
 *
 * @Description: Todo(PostString的请求方式)
 *
 * @author 赵屈犇
 *
 * @date 创建时间:2016/12/21 11:28
 *
 * @version 1.0
 */
public class PostStringRequest extends OkHttpRequest
{
    private static MediaType MEDIA_TYPE_PLAIN = MediaType.parse("text/plain;charset=utf-8");

    private String content;
    private MediaType mediaType;


    public PostStringRequest(String url, Object tag, Map<String, Object> params, Map<String, Object> headers, String content, MediaType mediaType,int id) {
        super(url, tag, params, headers,id);
        this.content = content;
        this.mediaType = mediaType;
        if (this.content == null) {
            this.content = "";
            //Exceptions.illegalArgument("内容不能为空!");
        }
        if (this.mediaType == null) {
            this.mediaType = MEDIA_TYPE_PLAIN;
        }

    }

    @Override
    protected RequestBody buildRequestBody() {
        return RequestBody.create(mediaType, content);
    }

    @Override
    protected Request buildRequest( RequestBody requestBody) {
        return builder.post(requestBody).build();
    }

}
